import { createRouter, createWebHistory } from "vue-router";
/* Layout */
import Layout from "@/layout";

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login"),
    hidden: true,
  },
  {
    path: "/register",
    component: () => import("@/views/register"),
    hidden: true,
  },
  // {
  //   path: "/:pathMatch(.*)*",
  //   component: () => import("@/views/error/404"),
  //   hidden: true,
  // },
  {
    path: "/401",
    component: () => import("@/views/error/401"),
    hidden: true,
  },
  {
    path: "",
    component: Layout,
    redirect: "/index",
    children: [
      {
        path: "/index",
        component: () => import("@/views/index"),
        name: "Index",
        meta: { title: "首页", icon: "dashboard", affix: true },
      },
    ],
  },
  {
    path: "/user",
    component: Layout,
    hidden: true,
    redirect: "noredirect",
    children: [
      {
        path: "profile",
        component: () => import("@/views/system/user/profile/index"),
        name: "Profile",
        meta: { title: "个人中心", icon: "user" },
      },
    ],
  },
];

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: "/baseConfig/contractTemplate-info", //不要和菜单配置的路径一样，不然不显示内容-评估机构的二级内容
    component: Layout,
    hidden: true,
    permissions: ['baseConfig:contractTemplate:list'],
    children: [
      {
        path: "contract-info/:id?/:content?/:status?/:illustration?/:name?",
        component: () => import('@/views/baseConfig/contractTemplate/info.vue'),
        name: "contract-info",
        props: true,
        meta: {
          title: "合同模板",
          activeMenu: "/baseConfig/contractTemplate",
        },
      },
    ],
  },

  {
    path: "/assessManagement/assessOrganization-people", //不要和菜单配置的路径一样，不然不显示内容-评估机构的二级内容
    component: Layout,
    hidden: true,
    permissions: ['assessManagement:assessOrganization:list'],
    children: [
      {
        path: "people/:id/:name",
        component: () =>
          import('@/views/assessManagement/assessOrganization/people.vue'),
        name: "people",
        props: true,
        meta: {
          title: "评估人员信息",
          activeMenu: "/assessManagement/assessOrganization",
        },
      },
    ],
  },

  {
    path: "/baseConfig/assessTemplate-info",
    component: Layout,
    hidden: true,
    permissions: ['baseConfig:assessTemplate:list'],
    children: [
      {
        path: "index/:id(\\d+)",
        component: () =>
          import('@/views/baseConfig/assessTemplate/addTemplate.vue'),
        name: "assessTemplate-info",
        meta: {
          title: '新增/修改评估模版',
          activeMenu: '/baseConfig/assessTemplate',
        },
      },
    ],
  },
  {
    path: "/communityManagement/communityPeople",
    component: Layout,
    hidden: true,
    permissions: ["communityManagement:communitySite:list"],
    children: [
      {
        path: "org/:id",
        component: () =>
          import('@/views/communityManagement/communitySite/people.vue'),
        name: "org",
        meta: {
          title: '站点人员',
          activeMenu: '/communityManagement/communitySite',
        },
      },
    ],
  },
  {
    path: "/homebedsign/evaluation-info",
    component: Layout,
    hidden: true,
    permissions: ['homebedsign:evaluation:list'],
    children: [
      {
        path: "info/:id",
        component: () =>
          import('@/views/homebedsign/evaluation/evalutationinfo.vue'),
        name: "info",
        meta: {
          title: "查看评估报告",
          activeMenu: "/homebedsign/evaluation",
        },
      },
    ],
  },
  {
    path: "/elderlyReform/ageReformApply",
    component: Layout,
    hidden: true,
    permissions: ['elderlyReform:ageReform:list'],
    children: [
      {
        path: "apply:id/:status/:showStatus",
        component: () =>
          import('@/views/elderlyReform/ageReform/ageReformApply.vue'),
        name: "ageReformApply",
        meta: {
          title: "适老化改造",
          activeMenu: "/elderlyReform/ageReform",
        },
      },
    ],
  },
  {
    path: "/elderlyReform/checkAcceptInfo",
    component: Layout,
    hidden: true,
    permissions: ['elderlyReform:checkAccept:list'],
    children: [
      {
        path: "checkAccept:id/:status",
        component: () =>
          import('@/views/elderlyReform/checkAccept/checkinfo.vue'),
        name: "checkAccept",
        meta: {
          title: "改造验收",
          activeMenu: "/elderlyReform/checkAccept",
        },
      },
    ],
  },
  {
    path: "/homebedsign/contractAwardInfo",
    component: Layout,
    hidden: true,
    permissions: ['homebedsign:contractAward:list'],
    children: [
      {
        path: "addOrInfo/:id",
        component: () =>
          import('@/views/homebedsign/contractAward/contractAward_info.vue'),
        name: "contractAwardInfo",
        meta: {
          title: "制定合同",
          activeMenu: "/homebedsign/contractAward",
        },
      },
    ],
  },
  {
    path: "/homebedsign/servicePlanInfo",
    component: Layout,
    hidden: true,
    permissions: ['homebedsign:servicePlan:list'],
    children: [
      {
        path: "makePlan/:id/:status",
        component: () =>
          import('@/views/homebedsign/servicePlan/servicePlanDetail.vue'),
        name: "servicePlanInfo",
        meta: {
          title: "制定服务计划",
          activeMenu: "/homebedsign/servicePlan",
        },
      },
    ],
  },
  {
    path: "/elderlyReform/elderlyReformInfo/:id/:step",
    component: Layout,
    hidden: true,
    permissions: ['elderlyReform:schedule:list'],
    children: [
      {
        path: "",
        component: () =>
          import('@/views/elderlyReform/schedule/scheduleInfo.vue'),
        name: "elderlyReformInfo",
        meta: {
          title: "查看改造进度",
          activeMenu: "/elderlyReform/schedule",
        },
      },
    ],
  },
  {
    path: "/ticketManagement/orderManagement/TicketDetails/:id/:status",
    component: Layout,
    hidden: true,
    permissions: ['ticketManagement:ticketManagement:list'],
    children: [
      {
        path: "",
        component: () =>
          import('@/views/ticketManagement/orderManagement/TicketDetails.vue'),
        name: "ticketDetails",
        meta: {
          title: "工单管理",
          activeMenu: "/ticketManagement/orderManagement",
        },
      },
    ],
  },
  {
    path: "/ticketManagement/returnVisitManagement/returnTicketDetails/:id/:status",
    component: Layout,
    hidden: true,
    permissions: ['ticketManagement:returnVisitManagement:list'],
    children: [
      {
        path: "",
        component: () =>
          import(
            '@/views/ticketManagement/returnVisitManagement/returnTicketDetails.vue'
          ),
        name: "returnTicketDetails",
        meta: {
          title: "工单回访",
          activeMenu: "/ticketManagement/returnVisitManagement",
        },
      },
    ],
  },
  {
    path: "/ticketManagement/scheduleTasks/scheduleDetails/:id",
    component: Layout,
    hidden: true,
    permissions: ['ticketManagement:scheduleTasks:list'],
    children: [
      {
        path: "",
        component: () =>
          import('@/views/ticketManagement/scheduleTasks/scheduleDetails.vue'),
        name: "scheduleDetails",
        meta: {
          title: "计划服务",
          activeMenu: "/ticketManagement/scheduleTasks",
        },
      },
    ],
  },
];
console.log('process.env.VUE_APP_BASE', process.env.VUE_APP_BASE)
const router = createRouter({
  history: createWebHistory(window.__POWERED_BY_QIANKUN__ ? '/homeBed' : '/'),
  // base: window.__POWERED_BY_QIANKUN__ ? "/vue3-admin" : "/",
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});
console.log(router, "<<<=== router 子应用的路由实例对象");
export default router;
